<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("platinumgrid/jtplatinumgrid.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class route_job_loc_list extends Page
{
       public $hfNumbering = null;
       public $JTJavaScript2 = null;
       public $hiddenLocId = null;
       public $JTJavaScript1 = null;
       public $hiddenJobId = null;
       public $hiddenType = null;
       public $JGridLocation = null;
       public $JTSiteTheme1 = null;
       function route_job_loc_listJSLoad($sender, $params)
       {

       ?>
       numbering = document.getElementById('hfNumbering').value;
       parent.document.getElementById('JTDivAddLocation_caption').innerHTML = "Location #"+numbering;
       parent.document.getElementById('edLocation').value = '';
       parent.document.getElementById('edClient').value = '';
       <?php

       }

       function JGridLocationJSDataLoad($sender, $params)
       {

       ?>
       var type = document.getElementById('hiddenType').value;
       if(type=='c')
       {
        parent.autofill('add');
       }
       if(type=='e')
       {
        parent.autofill('edit');
       }
       <?php

       }


       function JGridLocationShow($sender, $params)
       {
        $arr = array();
        $job_id = $this->hiddenJobId->getValue();

        if($job_id!='0')
        {
         $query_loc = "SELECT * FROM rou_job_loc_tbl WHERE company_id='".$_SESSION['company_id']."'
         AND job_id='".$job_id."' ORDER BY loc_id ASC";
        }
        if($job_id=='0')
        {
         $query_loc = "SELECT * FROM rou_job_loc_tbl WHERE company_id='".$_SESSION['company_id']."'
         AND temp_job_id ='".$_SESSION['temp_job_id']."' ORDER BY loc_id ASC";
        }

        $number = '1';
        $result_num = mysql_query($query_loc) or die("SELECT LOC ".mysql_error());
        while($row_num = mysql_fetch_array($result_num))
        {
         $loc_id = $row_num['loc_id'];
         $query_numbering = "UPDATE rou_job_loc_tbl SET loc_numbering='".$number."' WHERE loc_id='".$loc_id."'";
         mysql_query($query_numbering) or die("NUMBERING UPDATE ".mysql_error());
         $number++;
        }
        $this->hfNumbering->setValue($number);

        $result_loc = mysql_query($query_loc) or die("SELECT LOC ".mysql_error());
        while($row_loc = mysql_fetch_array($result_loc))
        {
          $loc = "<p style='color:blue;cursor:pointer' title='Edit' onclick=showEdit('".$row_loc['loc_id']."','".$row_loc['loc_numbering']."')><u>".$row_loc['loc_numbering']."&nbsp;".$row_loc['location']."</u></p>";
          $tot_hrs = $row_loc['hrs'];
          $miles = $row_loc['miles'];
          $tools2 = "<img onclick=js_deleteLoc('".$row_loc['loc_id']."'); src='image/delete.png' title='delete'>";

          if($_SESSION['access_route']==1)
          {
          $arr[] = array('Location'=>$loc,
          'Total Hours'=>$tot_hrs,
          'Kilometer'=>$miles);
          }

          if($_SESSION['access_route']==2)
          {
          $arr[] = array('Location'=>$loc,
          'Total Hours'=>$tot_hrs,
          'Kilometer'=>$miles,
          'Tools'=>$tools2);
          }

        }
        $this->JGridLocation->setCellData($arr);


       }

       function route_job_loc_listCreate($sender, $params)
       {
       $type = $_GET['type'];
       if($type!=null || $type!='')
       {
        $this->hiddenType->setValue($type);
       }

       if($this->hiddenType->getValue()=='e')
       {
        $job_id = $_GET['jobid'];
        if($job_id!=null || $job_id!='')
         {
          $this->hiddenJobId->setValue($job_id);
         }
       }
       if($this->hiddenType->getValue()=='c')
       {
          $this->hiddenJobId->setValue(0);
       }


       }

}

global $application;

global $route_job_loc_list;

//Creates the form
$route_job_loc_list=new route_job_loc_list($application);

//Read from resource file
$route_job_loc_list->loadResource(__FILE__);

//Shows the form
$route_job_loc_list->show();

?>